package com.example.demo.controller;

import com.example.demo.domain.GeneralResult;
import com.example.demo.model.User;
import com.example.demo.server.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@RestController
public class UserController {
    @Autowired
    static Map<Long, User> map = new ConcurrentHashMap<>();
    @Autowired
    private UserService userService;


    /***
     * 查询所有
     */
    @ApiOperation(value = "获取用户列表")
    @RequestMapping(value = "/selectall", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "phone", value = "手机号码", required = true, paramType = "query", dataType = "String"),
    })
//    @PostMapping("/selectall")
    public GeneralResult selectAll() {
        GeneralResult GeneralResult = new GeneralResult();
        List<User> userlistall = new ArrayList<>();
        if (null != userService.selectAll()) {
            userlistall = userService.selectAll();
            GeneralResult.setMsg("成功");
            GeneralResult.setData(userlistall);
            return GeneralResult;
        } else {
            GeneralResult.setMsg("成功");
            GeneralResult.setData("空");
            return GeneralResult;
        }
    }

//    /***
//     * 输入单条姓名进行删除单挑数据
//     */
//
//    @PostMapping("/deletebyid")
//    public Boolean deletebyusername(String username) {
//        System.out.println("usernaeme===" + username);
//        boolean
//                result = userService.deleteuserbyname(username);
//        return result;
//    }


    /***
     * 进行分页查询
     */
//    @RequestMapping(value = "/selectAllbytype", method = RequestMethod.PUT)
//    @ApiImplicitParams({
//    })
//    @ApiOperation(value = "用户登陆进行查询带分页")
//    @ApiResponses({
//            @ApiResponse(code = 400, message = "请求参数没填好"),
//            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
//    })
//    @GetMapping
//    @PostMapping("/selectAllbytype")
//    public Result selectAllbytype(UserListQuery userListQuery) {
//        GeneralResult generalResult = new GeneralResult();
//        PageBO<User> systemUserList = userService.selectType(userListQuery);
//        generalResult.setData(systemUserList);
//        generalResult.setCode(00);
//        if (null != systemUserList) {
//            return generalResult;
//        } else {
//            generalResult.setData("数据返回为null");
//            generalResult.setCode(99);
//
//            return null;
//        }
//
//    }

}
